package com.iie.bigVideo.controller;


import com.iie.bigVideo.entity.SysUser;
import com.iie.bigVideo.entity.User;
import com.iie.bigVideo.entity.dto.UserDto;
import com.iie.bigVideo.mapper.UserMapper;
import com.iie.bigVideo.service.SysUserService;
import com.iie.bigVideo.service.UserService;
import com.iie.bigVideo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author XXX
 * @since 2023-11-19
 */
@RestController
@RequestMapping("/sys-user")
@CrossOrigin //跨域
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private UserService userService;

    /**
     * 管理员登录
     *
     * @param userName
     * @param password
     * @return
     */
    @PostMapping("/login")
    public ResultVO<SysUser> userLogin(@RequestParam("userName") String userName, @RequestParam("password") String password) {
        return sysUserService.userLogin(userName, password);
    }

    /**
     * 管理员修改密码
     *
     * @param id
     * @param password
     * @return
     */
    @PostMapping("/updatePassword")
    public ResultVO updatePassword(@RequestParam("id") int id, @RequestParam("password") String password) {
        return sysUserService.updatePassword(id, password);
    }

    /**
     * 分页查询普通用户
     *
     * @param current           页码
     * @param size              每页的数量
     * @param userName          用户名
     * @param userPhone         用户手机号
     * @param nurserySchoolName 园区名
     * @return
     */
    @GetMapping("/queryUserList/{current}/{size}")
    public ResultVO queryUser(@PathVariable("current") int current, @PathVariable("size") int size, @RequestParam(value = "userName", required = false) String userName, @RequestParam(value = "userPhone", required = false) String userPhone, @RequestParam(value = "nurserySchoolName", required = false) String nurserySchoolName) {
        User user = new User();
        user.setUserName(userName);
        user.setUserPhone(userPhone);
        user.setNurserySchoolName(nurserySchoolName);
        return userService.queryUserList(current, size, user);
    }

    /**
     * 新增普通用户
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/addUser")
    public ResultVO addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    /**
     * 修改普通用户
     *
     * @param user
     * @return
     */
    @PostMapping("/updateUser")
    public ResultVO updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    /**
     * 修改普通用户状态
     *
     * @param id       普通用户ID
     * @param isDelete 状态：0 启用  1禁用
     * @return
     */
    @PostMapping("/updateStateByUserID")
    public ResultVO updateStateByUserID(@RequestParam("id") int id, @RequestParam("isDelete") int isDelete) {
        return userService.updateStateByUserID(id, isDelete);
    }


    /**
     * 删除普通用户
     */
    @GetMapping("/deleteUser/{id}")
    public ResultVO deleteUser(@PathVariable("id") int id) {
        return userService.deleteUser(id);
    }


    /**
     * 导出excel模板
     *
     * @return
     */
    @GetMapping("/outExcel")
    public ResultVO outExcel() {
        return sysUserService.outExcel();
    }

    /**
     * 导入excel
     */
    @PostMapping("/inputExcel")
    public ResultVO inputExcel(@RequestParam(value = "excelFile", required = false) MultipartFile excelFile) {
        return sysUserService.inputExcel(excelFile);
    }


}

